package com.xxgc.eow.service.impl;

import com.xxgc.eow.entity.Likecomment;
import com.xxgc.eow.mapper.LikecommentMapper;
import com.xxgc.eow.service.ILikecommentService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.Date;

/**
 * <p>
 * 点赞一级评论表 服务实现类
 * </p>
 *
 * @author Mr.Abel
 * @since 2023-05-27
 */
@Service
public class LikecommentServiceImpl extends ServiceImpl<LikecommentMapper, Likecomment> implements ILikecommentService {

    @Resource
    private LikecommentMapper likecommentMapper;

    @Override
    public int insertLikeComment(Likecomment likecomment) {
        Date date = new Date();
        Instant instant = date.toInstant();
        ZoneId zoneId = ZoneId.systemDefault();
        LocalDateTime localDateTime = instant.atZone(zoneId).toLocalDateTime();
        likecomment.setCreateTime(localDateTime);
        return likecommentMapper.insertLikeComment(likecomment);
    }

    @Override
    public Integer getCommentLikeById(int commentId) {
        return likecommentMapper.getLikeNumByCommentId(commentId);
    }

    @Override
    public int updateCommentLike(int commentId, int likeNum) {
        return likecommentMapper.updateCommentLike(commentId,likeNum);
    }

    @Override
    public int delCommentLike(Likecomment likecomment) {
        Date date = new Date();
        Instant instant = date.toInstant();
        ZoneId zoneId = ZoneId.systemDefault();
        LocalDateTime localDateTime = instant.atZone(zoneId).toLocalDateTime();
        likecomment.setDestroyTime(localDateTime);
        return likecommentMapper.delLikeComment(likecomment);
    }

    @Override
    public Likecomment selectDataTf(Likecomment likecomment) {
        return likecommentMapper.selectDataTf(likecomment);
    }

    @Override
    public Likecomment selectById(int commentId) {
        return likecommentMapper.selectById(commentId);
    }
}
